package vn.com.shoppie.activity;

import android.app.Dialog;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.widget.TextView;

public class BluetoothDialog extends Dialog {
	public int TIME_DISCOVERING = 20; // second

	BluetoothAdapter mBluetoothAdapter;
	TextView tv;

	public BluetoothDialog(Context context) {
		super(context);
		setContentView(R.layout.dialog_bluetooth);
		setTitle(context.getResources().getString(R.string.app_name));

		tv = (TextView) findViewById(R.id.tv_status);

		mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
		if (mBluetoothAdapter == null) {
			tv.setText("Device not supported");
		}

		setCancelable(true);
		setCanceledOnTouchOutside(true);
		
		turnBluetoothDiscover(TIME_DISCOVERING);
	}


	public boolean turnBluetooth(boolean on) {
		if (on) {
			tv.append("Turning ON bluetooth\n");
			if (!mBluetoothAdapter.isEnabled()) {
				tv.append("BlueTooth is enabled\n");
				return mBluetoothAdapter.enable();
			}
			return true;
		} else {
			tv.append("Turning OFF bluetooth\n");
			if (mBluetoothAdapter.isEnabled()) {
				tv.append("BlueTooth is disabled\n");
				return mBluetoothAdapter.disable();
			}
			return false;
		}
	}

	public void turnBluetoothDiscover(final int duration) {
		
	}
}
